package com.jiandan.meizi;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
import com.jiandan.utils.HtmlParser;
import com.jiandan.utils.SimpleHttpClient;
import com.jiandan.utils.Tools;

/**
 * jandan.net/new 列表点击详细显示
 * 
 * @author Mr.He
 * 
 */
public class JanDanNewDetailactivity extends Activity implements Runnable {

    private String url;
    private WebView webview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jandan_new_detail);
        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setLoadWithOverviewMode(true);
        
        WebSettings setting = webview.getSettings();
        setting.setDefaultFontSize(18);
        
        url = getIntent().getStringExtra("url");

        Tools.buildLoadingDialog(this);

        new Thread(this).start();

    }

    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {

            Tools.progressDialogDissmiss();

            if (msg.obj == null)
                Toast.makeText(JanDanNewDetailactivity.this, "请求失败，请重试", Toast.LENGTH_LONG).show();
            else
                webview.loadDataWithBaseURL(null, (String) msg.obj, "text/html", "utf-8", null);

        }

    };

    @Override
    public void run() {
        try {
            Message msg = handler.obtainMessage();
            SimpleHttpClient client = new SimpleHttpClient();
            HtmlParser parse = new HtmlParser(url);
            parse.setHtml(client.get(url));
            parse.setActivity(this);
            msg.obj = parse.handlerNewDetails();
            msg.sendToTarget();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
